import { NRow, type RowProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";

export type RowFactoryConstructorType = {
  props?: RowProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
};

export class RowFactory {
  private props: RowProps = {};
  private attrs: HTMLAttributes = {};
  private defaultSlot: BaseComponentType = null;

  constructor(data?: RowFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: RowProps) {
    this.props = props;
    return this;
  }
  setDefault(defaultSlot: BaseComponentType) {
    this.defaultSlot = defaultSlot;
    return this;
  }

  create() {
    return (
      <NRow {...this.attrs} {...this.props}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
        }}
      </NRow>
    );
  }
}
